package com.chenxi.controller;

import com.chenxi.VO.ResourceMenuVO;
import com.chenxi.common.controller.BaseController;
import com.chenxi.model.SysResource;
import com.chenxi.service.ISysResourceService;
import com.chenxi.util.PageData;
import com.chenxi.util.PageForm;
import com.chenxi.util.ResultJson;
import com.google.common.collect.Lists;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * ${DESCRIPTION}
 *
 * @author Hu Xiaolong
 * @version V0.1
 * @create 2017/12/21
 */
@RestController
@RequestMapping("/resourceApi/")
public class ResourceController extends BaseController {

    @Autowired
    private ISysResourceService sysResourceService;

    @RequestMapping("loadMenuList")
    public ResultJson loadMenuList(Long userId){
        ResultJson r = super.getSuccess();
        List<ResourceMenuVO> menus = sysResourceService.loadMenuResources(userId);
        r.setData(menus);
        return r;
    }

    @RequestMapping(value = "page")
    public ResultJson page(HttpServletRequest request, PageForm pageForm){
        ResultJson rj = super.getSuccess();
        PageData<SysResource> resourcePageData = sysResourceService.page(pageForm);
        rj.setData(resourcePageData);
        return rj;
    }
}
